#ifndef __TOOL_FIFO_H
#define __TOOL_FIFO_H

#if __cplusplus
extern "C"
{
#endif

#include "bsp_Inc.h"

#if __cplusplus
}
#endif

#if __cplusplus

typedef unsigned char QUEUE_DATA_T;

class tool_Fifo
{
private:
    unsigned int head;          // 队列头指针
    unsigned int tail;          // 队列尾指针
    unsigned int buffer_length; // 队列缓存长度（初始化时赋值）

public:
    typedef enum
    {
        QUEUE_OK = 0x00U,           // 队列OK
        QUEUE_ERROR = 0x01U,        // 队列错误
        QUEUE_BUSY = 0x02U,         // 队列忙
        QUEUE_TIMEOUT = 0x03U,      // 队列超时
        QUEUE_OVERLOAD = 0x04U,     // 队列已满
        QUEUE_VOID = 0x05U,         // 队列已空
        QUEUE_INSUFFICIENT = 0x06U, // 队列不足
        QUEUE_MISS = 0x07U,         // 队列内容缺少
    } QUEUE_ret;
    QUEUE_DATA_T *buffer; // 队列缓存数组（初始化时赋值）

    tool_Fifo(QUEUE_DATA_T *buffer, int length)
    {
        this->buffer = buffer;
        this->buffer_length = length;
        this->head = 0;
        this->tail = 0;
    }
    ~tool_Fifo()
    {
    }
    int getCount();
    QUEUE_ret push(QUEUE_DATA_T pData);
    QUEUE_ret pop(QUEUE_DATA_T *pData);
    QUEUE_ret pushArray(QUEUE_DATA_T *pData, int size);
    QUEUE_ret popArray(QUEUE_DATA_T *pData, int size);
    void clear();
};

#if DEMO_FIFO
extern tool_Fifo demoFifo;
#endif

#endif

#endif
